﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Acms.DatabaseTest.Helpers
{
    public static class DBHelpers
    {

        public static void ControlType_Add(this TestConnection conn, int id, int? siteId, string name, string adminControlType, string adminEditControlType, string adminDisplayControlType, string frontEndControlType, string notes, bool? custom, bool? deleted)
        {
            string sql = @"
            
            set identity_insert acms.ControlTypes on 

            INSERT INTO [acms].ControlTypes ([Id], [SiteId], [Name], [AdminControlType], [AdminEditControlType], [AdminDisplayControlType], [FrontEndControlType], [Notes], [Custom], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9)
            
            set identity_insert acms.ControlTypes off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, adminControlType)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, adminEditControlType)
				.AddInputParam("@5", System.Data.SqlDbType.VarChar, adminDisplayControlType)
				.AddInputParam("@6", System.Data.SqlDbType.VarChar, frontEndControlType)
				.AddInputParam("@7", System.Data.SqlDbType.VarChar, notes)
				.AddInputParam("@8", System.Data.SqlDbType.Bit, custom)
				.AddInputParam("@9", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> ControlType_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.ControlTypes");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> ControlType_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.ControlTypes where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void CustomAdminPage_Add(this TestConnection conn, int id, int siteId, string name, string controlPath, string notes, int sequence, byte section, bool deleted)
        {
            string sql = @"
            
            set identity_insert acms.CustomAdminPage on 

            INSERT INTO [acms].CustomAdminPage ([Id], [SiteId], [Name], [ControlPath], [Notes], [Sequence], [Section], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7)
            
            set identity_insert acms.CustomAdminPage off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, controlPath)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, notes)
				.AddInputParam("@5", System.Data.SqlDbType.Int, sequence)
				.AddInputParam("@6", System.Data.SqlDbType.TinyInt, section)
				.AddInputParam("@7", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> CustomAdminPage_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.CustomAdminPage");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> CustomAdminPage_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.CustomAdminPage where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void Email_Add(this TestConnection conn, int id, int? userId, string emailAddress, string name, string filePath, string to, string cc, string bcc, string from, string replyTo, string subject, string body, bool? html, DateTime created, DateTime? sent, bool failed)
        {
            string sql = @"
            
            set identity_insert acms.Email on 

            INSERT INTO [acms].Email ([Id], [UserId], [EmailAddress], [Name], [FilePath], [To], [Cc], [Bcc], [From], [ReplyTo], [Subject], [Body], [Html], [Created], [Sent], [Failed])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15)
            
            set identity_insert acms.Email off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, emailAddress)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, filePath)
				.AddInputParam("@5", System.Data.SqlDbType.VarChar, to)
				.AddInputParam("@6", System.Data.SqlDbType.VarChar, cc)
				.AddInputParam("@7", System.Data.SqlDbType.VarChar, bcc)
				.AddInputParam("@8", System.Data.SqlDbType.VarChar, from)
				.AddInputParam("@9", System.Data.SqlDbType.VarChar, replyTo)
				.AddInputParam("@10", System.Data.SqlDbType.VarChar, subject)
				.AddInputParam("@11", System.Data.SqlDbType.VarChar, body)
				.AddInputParam("@12", System.Data.SqlDbType.Bit, html)
				.AddInputParam("@13", System.Data.SqlDbType.DateTime, created)
				.AddInputParam("@14", System.Data.SqlDbType.DateTime, sent)
				.AddInputParam("@15", System.Data.SqlDbType.Bit, failed)
            );
        }

        public static List<Dictionary<string, object>> Email_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Email");
            return source.ExecuteWithResults(sql);
        }
		

        public static void EmailActivationCode_Add(this TestConnection conn, int id, int userId, string emailAddress, string code, DateTime? activated, DateTime created, bool deleted)
        {
            string sql = @"
            
            set identity_insert acms.EmailActivationCode on 

            INSERT INTO [acms].EmailActivationCode ([Id], [UserId], [EmailAddress], [Code], [Activated], [Created], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5, @6)
            
            set identity_insert acms.EmailActivationCode off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, emailAddress)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, code)
				.AddInputParam("@4", System.Data.SqlDbType.DateTime, activated)
				.AddInputParam("@5", System.Data.SqlDbType.DateTime, created)
				.AddInputParam("@6", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> EmailActivationCode_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.EmailActivationCode");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> EmailActivationCode_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.EmailActivationCode where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void ExceptionLog_Add(this TestConnection conn, int id, string serverName, string applicationRoot, string url, string rawUrl, int? postId, int? siteId, string exceptionType, string exceptionMessage, string innerExceptionType, string innerExceptionMessage, string source, string stackTrace, DateTime created)
        {
            string sql = @"
            
            set identity_insert acms.ExceptionLog on 

            INSERT INTO [acms].ExceptionLog ([Id], [ServerName], [ApplicationRoot], [Url], [RawUrl], [PostId], [SiteId], [ExceptionType], [ExceptionMessage], [InnerExceptionType], [InnerExceptionMessage], [Source], [StackTrace], [Created])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13)
            
            set identity_insert acms.ExceptionLog off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.VarChar, serverName)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, applicationRoot)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, url)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, rawUrl)
				.AddInputParam("@5", System.Data.SqlDbType.Int, postId)
				.AddInputParam("@6", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@7", System.Data.SqlDbType.VarChar, exceptionType)
				.AddInputParam("@8", System.Data.SqlDbType.VarChar, exceptionMessage)
				.AddInputParam("@9", System.Data.SqlDbType.VarChar, innerExceptionType)
				.AddInputParam("@10", System.Data.SqlDbType.VarChar, innerExceptionMessage)
				.AddInputParam("@11", System.Data.SqlDbType.VarChar, source)
				.AddInputParam("@12", System.Data.SqlDbType.VarChar, stackTrace)
				.AddInputParam("@13", System.Data.SqlDbType.DateTime, created)
            );
        }

        public static List<Dictionary<string, object>> ExceptionLog_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.ExceptionLog");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> ExceptionLog_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.ExceptionLog where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void FileDownload_Add(this TestConnection conn, int id, int fileId, int? userId, string iPAddress, string path, string name, DateTime created)
        {
            string sql = @"
            
            set identity_insert acms.FileDownload on 

            INSERT INTO [acms].FileDownload ([Id], [FileId], [UserId], [IPAddress], [Path], [Name], [Created])
			VALUES (@0, @1, @2, @3, @4, @5, @6)
            
            set identity_insert acms.FileDownload off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, fileId)
				.AddInputParam("@2", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, iPAddress)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, path)
				.AddInputParam("@5", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@6", System.Data.SqlDbType.DateTime, created)
            );
        }

        public static List<Dictionary<string, object>> FileDownload_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.FileDownload");
            return source.ExecuteWithResults(sql);
        }
		

        public static void File_Add(this TestConnection conn, int id, byte[] fileData, string name, long size, int fileType, string contentType, string extension, int? width, int? height, bool logDownload, bool? deleted)
        {
            string sql = @"
            
            set identity_insert acms.Files on 

            INSERT INTO [acms].Files ([Id], [FileData], [Name], [Size], [FileType], [ContentType], [Extension], [Width], [Height], [LogDownload], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10)
            
            set identity_insert acms.Files off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.VarBinary, fileData)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.BigInt, size)
				.AddInputParam("@4", System.Data.SqlDbType.Int, fileType)
				.AddInputParam("@5", System.Data.SqlDbType.VarChar, contentType)
				.AddInputParam("@6", System.Data.SqlDbType.VarChar, extension)
				.AddInputParam("@7", System.Data.SqlDbType.Int, width)
				.AddInputParam("@8", System.Data.SqlDbType.Int, height)
				.AddInputParam("@9", System.Data.SqlDbType.Bit, logDownload)
				.AddInputParam("@10", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> File_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Files");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> File_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.Files where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void MasterPage_Add(this TestConnection conn, int id, int siteId, string name, string path, bool isdefault, bool deleted)
        {
            string sql = @"
            
            set identity_insert acms.MasterPages on 

            INSERT INTO [acms].MasterPages ([Id], [SiteId], [Name], [Path], [Default], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5)
            
            set identity_insert acms.MasterPages off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, path)
				.AddInputParam("@4", System.Data.SqlDbType.Bit, isdefault)
				.AddInputParam("@5", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> MasterPage_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.MasterPages");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> MasterPage_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.MasterPages where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void Menu_Add(this TestConnection conn, int id, int siteId, string name, string parentPath, bool? includeParent, bool? defaultForAllPosts, string notes, bool? deleted)
        {
            string sql = @"
            
            set identity_insert acms.Menus on 

            INSERT INTO [acms].Menus ([Id], [SiteId], [Name], [ParentPath], [IncludeParent], [DefaultForAllPosts], [Notes], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7)
            
            set identity_insert acms.Menus off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, parentPath)
				.AddInputParam("@4", System.Data.SqlDbType.Bit, includeParent)
				.AddInputParam("@5", System.Data.SqlDbType.Bit, defaultForAllPosts)
				.AddInputParam("@6", System.Data.SqlDbType.VarChar, notes)
				.AddInputParam("@7", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> Menu_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Menus");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> Menu_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.Menus where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void PostControl_Add(this TestConnection conn, int id, int postId, int templateControlId, XmlDocument value, bool? deleted)
        {
            string sql = @"
            
            set identity_insert acms.PostControls on 

            INSERT INTO [acms].PostControls ([Id], [PostId], [TemplateControlId], [Value], [Deleted])
			VALUES (@0, @1, @2, @3, @4)
            
            set identity_insert acms.PostControls off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, postId)
				.AddInputParam("@2", System.Data.SqlDbType.Int, templateControlId)
				.AddInputParam("@3", System.Data.SqlDbType.Xml, value)
				.AddInputParam("@4", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> PostControl_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.PostControls");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> PostControl_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.PostControls where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void PostMenu_Add(this TestConnection conn, int id, int menuId, int postId, bool included, bool deleted)
        {
            string sql = @"
            
            set identity_insert acms.PostMenu on 

            INSERT INTO [acms].PostMenu ([Id], [MenuId], [PostId], [Included], [Deleted])
			VALUES (@0, @1, @2, @3, @4)
            
            set identity_insert acms.PostMenu off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, menuId)
				.AddInputParam("@2", System.Data.SqlDbType.Int, postId)
				.AddInputParam("@3", System.Data.SqlDbType.Bit, included)
				.AddInputParam("@4", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> PostMenu_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.PostMenu");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> PostMenu_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.PostMenu where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void PostPosition_Add(this TestConnection conn, Guid id, int postId, DateTime? publishDate, string parentPath, int? sequence, string parentSequence)
        {
            string sql = @"
            INSERT INTO [acms].PostPositions ([Id], [PostId], [PublishDate], [ParentPath], [Sequence], [ParentSequence])
			VALUES (@0, @1, @2, @3, @4, @5)
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.UniqueIdentifier, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, postId)
				.AddInputParam("@2", System.Data.SqlDbType.DateTime, publishDate)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, parentPath)
				.AddInputParam("@4", System.Data.SqlDbType.Int, sequence)
				.AddInputParam("@5", System.Data.SqlDbType.VarChar, parentSequence)
            );
        }

        public static List<Dictionary<string, object>> PostPosition_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.PostPositions order by parentpath");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> PostPosition_Get(this TestConnection source, Guid id)
        {
            string sql = "select * from acms.PostPositions where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.UniqueIdentifier, id)
                ).FirstOrDefault();
        }
	

        public static void PostPositions2_Add(this TestConnection conn, Guid id, int postId, DateTime? publishDate, string parentPath, int? sequence, string parentSequence)
        {
            string sql = @"
            
            set identity_insert acms.PostPositions2 on 

            INSERT INTO [acms].PostPositions2 ([Id], [PostId], [PublishDate], [ParentPath], [Sequence], [ParentSequence])
			VALUES (@0, @1, @2, @3, @4, @5)
            
            set identity_insert acms.PostPositions2 off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.UniqueIdentifier, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, postId)
				.AddInputParam("@2", System.Data.SqlDbType.DateTime, publishDate)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, parentPath)
				.AddInputParam("@4", System.Data.SqlDbType.Int, sequence)
				.AddInputParam("@5", System.Data.SqlDbType.VarChar, parentSequence)
            );
        }

        public static List<Dictionary<string, object>> PostPositions2_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.PostPositions2");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> PostPositions2_Get(this TestConnection source, Guid id)
        {
            string sql = "select * from acms.PostPositions2 where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.UniqueIdentifier, id)
                ).FirstOrDefault();
        }
	

        public static void Post_Add(this TestConnection conn, int id, int siteId, Guid postGuid, Guid parentGuid, string name, string displayName, int sequence, int? templateId, int? thumbnailId, string summary, DateTime createdDateTime, DateTime? publishFrom, DateTime? publishTo, string notes, bool requiresPublishing, bool readyToPublish, bool developerLocked, bool deleted, string titleSummary, string metaKeywords)
        {
            string sql = @"
            
            set identity_insert acms.Posts on 

            INSERT INTO [acms].Posts ([Id], [SiteId], [PostGuid], [ParentGuid], [Name], [DisplayName], [Sequence], [TemplateId], [ThumbnailId], [Summary], [CreatedDateTime], [PublishFrom], [PublishTo], [Notes], [RequiresPublishing], [ReadyToPublish], [DeveloperLocked], [Deleted], [TitleSummary], [MetaKeywords])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @19, @20)
            
            set identity_insert acms.Posts off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.UniqueIdentifier, postGuid)
				.AddInputParam("@3", System.Data.SqlDbType.UniqueIdentifier, parentGuid)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@5", System.Data.SqlDbType.VarChar, displayName)
				.AddInputParam("@6", System.Data.SqlDbType.Int, sequence)
				.AddInputParam("@7", System.Data.SqlDbType.Int, templateId)
				.AddInputParam("@8", System.Data.SqlDbType.Int, thumbnailId)
				.AddInputParam("@9", System.Data.SqlDbType.VarChar, summary)
				.AddInputParam("@10", System.Data.SqlDbType.DateTime, createdDateTime)
				.AddInputParam("@11", System.Data.SqlDbType.DateTime, publishFrom)
				.AddInputParam("@12", System.Data.SqlDbType.DateTime, publishTo)
				.AddInputParam("@13", System.Data.SqlDbType.VarChar, notes)
				.AddInputParam("@14", System.Data.SqlDbType.Bit, requiresPublishing)
				.AddInputParam("@15", System.Data.SqlDbType.Bit, readyToPublish)
				.AddInputParam("@16", System.Data.SqlDbType.Bit, developerLocked)
				.AddInputParam("@17", System.Data.SqlDbType.Bit, deleted)
				.AddInputParam("@19", System.Data.SqlDbType.VarChar, titleSummary)
				.AddInputParam("@20", System.Data.SqlDbType.VarChar, metaKeywords)
            );
        }

        public static List<Dictionary<string, object>> Post_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Posts");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> Post_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.Posts where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void PostTopic_Add(this TestConnection conn, int postId, int topicId, bool deleted)
        {
            string sql = @"
            
            set identity_insert acms.PostTopics on 

            INSERT INTO [acms].PostTopics ([PostId], [TopicId], [Deleted])
			VALUES (@0, @1, @2)
            
            set identity_insert acms.PostTopics off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, postId)
				.AddInputParam("@1", System.Data.SqlDbType.Int, topicId)
				.AddInputParam("@2", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> PostTopic_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.PostTopics");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> PostTopic_Get(this TestConnection source, int postId, int topicId)
        {
            string sql = "select * from acms.PostTopics where PostId = @0 and TopicId = @1";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, postId)
				.AddInputParam("@1", System.Data.SqlDbType.Int, topicId)
                ).FirstOrDefault();
        }
	

        public static void Redirect_Add(this TestConnection conn, int id, int siteId, string originalUrl, string targetUrl, int httpCode)
        {
            string sql = @"
            
            set identity_insert acms.Redirect on 

            INSERT INTO [acms].Redirect ([Id], [SiteId], [OriginalUrl], [TargetUrl], [HttpCode])
			VALUES (@0, @1, @2, @3, @4)
            
            set identity_insert acms.Redirect off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, originalUrl)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, targetUrl)
				.AddInputParam("@4", System.Data.SqlDbType.Int, httpCode)
            );
        }

        public static List<Dictionary<string, object>> Redirect_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Redirect");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> Redirect_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.Redirect where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void Role_Add(this TestConnection conn, int id, int? siteId, string name, string description, bool isAdminRole, DateTime created, bool deleted)
        {
            string sql = @"
            
            set identity_insert acms.Role on 

            INSERT INTO [acms].Role ([Id], [SiteId], [Name], [Description], [IsAdminRole], [Created], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5, @6)
            
            set identity_insert acms.Role off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, description)
				.AddInputParam("@4", System.Data.SqlDbType.Bit, isAdminRole)
				.AddInputParam("@5", System.Data.SqlDbType.DateTime, created)
				.AddInputParam("@6", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> Role_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Role");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> Role_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.Role where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void SearchTerm_Add(this TestConnection conn, int id, int siteId, string term, int count, bool excluded)
        {
            string sql = @"
            
            set identity_insert acms.SearchTerms on 

            INSERT INTO [acms].SearchTerms ([Id], [SiteId], [Term], [Count], [Excluded])
			VALUES (@0, @1, @2, @3, @4)
            
            set identity_insert acms.SearchTerms off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, term)
				.AddInputParam("@3", System.Data.SqlDbType.Int, count)
				.AddInputParam("@4", System.Data.SqlDbType.Bit, excluded)
            );
        }

        public static List<Dictionary<string, object>> SearchTerm_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.SearchTerms");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> SearchTerm_Get(this TestConnection source, string term)
        {
            string sql = "select * from acms.SearchTerms where Term = @2";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, term)
                ).FirstOrDefault();
        }
	

        public static void SiteMapping_Add(this TestConnection conn, int id, int siteId, string mappingName)
        {
            string sql = @"
            
            set identity_insert acms.SiteMappings on 

            INSERT INTO [acms].SiteMappings ([Id], [SiteId], [MappingName])
			VALUES (@0, @1, @2)
            
            set identity_insert acms.SiteMappings off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, mappingName)
            );
        }

        public static List<Dictionary<string, object>> SiteMapping_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.SiteMappings");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> SiteMapping_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.SiteMappings where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void Site_Add(this TestConnection conn, int id, string name, string root, bool useTopics, bool useMenus, bool? deleted)
        {
            string sql = @"
            
            set identity_insert acms.Sites on 

            INSERT INTO [acms].Sites ([Id], [Name], [Root], [UseTopics], [UseMenus], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5)
            
            set identity_insert acms.Sites off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, root)
				.AddInputParam("@3", System.Data.SqlDbType.Bit, useTopics)
				.AddInputParam("@4", System.Data.SqlDbType.Bit, useMenus)
				.AddInputParam("@5", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> Site_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Sites");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> Site_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.Sites where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void TemplateControl_Add(this TestConnection conn, int id, int templateId, string name, int? typeId, string notes, int sequence, bool? deleted)
        {
            string sql = @"
            
            set identity_insert acms.TemplateControls on 

            INSERT INTO [acms].TemplateControls ([Id], [TemplateId], [Name], [TypeId], [Notes], [Sequence], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5, @6)
            
            set identity_insert acms.TemplateControls off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, templateId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.Int, typeId)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, notes)
				.AddInputParam("@5", System.Data.SqlDbType.Int, sequence)
				.AddInputParam("@6", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> TemplateControl_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.TemplateControls");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> TemplateControl_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.TemplateControls where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void TemplateFile_Add(this TestConnection conn, int id, int templateId, string name, string path, string masterPagePath, string theme, bool isDefault, bool deleted)
        {
            string sql = @"
            
            set identity_insert acms.TemplateFiles on 

            INSERT INTO [acms].TemplateFiles ([Id], [TemplateId], [Name], [Path], [MasterPagePath], [Theme], [IsDefault], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7)
            
            set identity_insert acms.TemplateFiles off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, templateId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, path)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, masterPagePath)
				.AddInputParam("@5", System.Data.SqlDbType.VarChar, theme)
				.AddInputParam("@6", System.Data.SqlDbType.Bit, isDefault)
				.AddInputParam("@7", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> TemplateFile_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.TemplateFiles");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> TemplateFile_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.TemplateFiles where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void TemplateHierarchy_Add(this TestConnection conn, int id, int parentId, int childId, int sequence)
        {
            string sql = @"
            
            set identity_insert acms.TemplateHierarchy on 

            INSERT INTO [acms].TemplateHierarchy ([Id], [ParentId], [ChildId], [Sequence])
			VALUES (@0, @1, @2, @3)
            
            set identity_insert acms.TemplateHierarchy off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, parentId)
				.AddInputParam("@2", System.Data.SqlDbType.Int, childId)
				.AddInputParam("@3", System.Data.SqlDbType.Int, sequence)
            );
        }

        public static List<Dictionary<string, object>> TemplateHierarchy_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.TemplateHierarchy");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> TemplateHierarchy_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.TemplateHierarchy where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void Template_Add(this TestConnection conn, int id, int siteId, string name, string notes, int nodeType, bool excludeFromSearch, bool? deleted)
        {
            string sql = @"
            
            set identity_insert acms.Templates on 

            INSERT INTO [acms].Templates ([Id], [SiteId], [Name], [Notes], [NodeType], [ExcludeFromSearch], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5, @6)
            
            set identity_insert acms.Templates off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, notes)
				.AddInputParam("@4", System.Data.SqlDbType.Int, nodeType)
				.AddInputParam("@5", System.Data.SqlDbType.Bit, excludeFromSearch)
				.AddInputParam("@6", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> Template_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Templates");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> Template_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.Templates where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void TopicFile_Add(this TestConnection conn, int id, int? topicId, int? fileId, string name, bool? deleted)
        {
            string sql = @"
            
            set identity_insert acms.TopicFiles on 

            INSERT INTO [acms].TopicFiles ([Id], [TopicId], [FileId], [Name], [Deleted])
			VALUES (@0, @1, @2, @3, @4)
            
            set identity_insert acms.TopicFiles off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, topicId)
				.AddInputParam("@2", System.Data.SqlDbType.Int, fileId)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@4", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> TopicFile_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.TopicFiles");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> TopicFile_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.TopicFiles where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void TopicGroup_Add(this TestConnection conn, int id, int siteId, string name, string path, string notes, DateTime created, bool deleted)
        {
            string sql = @"
            
            set identity_insert acms.TopicGroup on 

            INSERT INTO [acms].TopicGroup ([Id], [SiteId], [Name], [Path], [Notes], [Created], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5, @6)
            
            set identity_insert acms.TopicGroup off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, path)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, notes)
				.AddInputParam("@5", System.Data.SqlDbType.DateTime, created)
				.AddInputParam("@6", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> TopicGroup_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.TopicGroup");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> TopicGroup_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.TopicGroup where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void Topic_Add(this TestConnection conn, int id, int topicGroupId, string name, int sequence, DateTime created, bool? deleted)
        {
            string sql = @"
            
            set identity_insert acms.Topics on 

            INSERT INTO [acms].Topics ([Id], [TopicGroupId], [Name], [Sequence], [Created], [Deleted])
			VALUES (@0, @1, @2, @3, @4, @5)
            
            set identity_insert acms.Topics off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, topicGroupId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.Int, sequence)
				.AddInputParam("@4", System.Data.SqlDbType.DateTime, created)
				.AddInputParam("@5", System.Data.SqlDbType.Bit, deleted)
            );
        }

        public static List<Dictionary<string, object>> Topic_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Topics");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> Topic_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.Topics where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void UserCustomProperty_Add(this TestConnection conn, int id, int userId, string name, string value)
        {
            string sql = @"
            
            set identity_insert acms.UserCustomProperty on 

            INSERT INTO [acms].UserCustomProperty ([Id], [UserId], [Name], [Value])
			VALUES (@0, @1, @2, @3)
            
            set identity_insert acms.UserCustomProperty off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, name)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, value)
            );
        }

        public static List<Dictionary<string, object>> UserCustomProperty_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.UserCustomProperty");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> UserCustomProperty_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.UserCustomProperty where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void UserLoginKey_Add(this TestConnection conn, Guid key, int userId, DateTime? loggedIn, DateTime? lastAccessed, bool? perminant)
        {
            string sql = @"
            
            set identity_insert acms.UserLoginKeys on 

            INSERT INTO [acms].UserLoginKeys ([Key], [UserId], [LoggedIn], [LastAccessed], [Perminant])
			VALUES (@0, @1, @2, @3, @4)
            
            set identity_insert acms.UserLoginKeys off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.UniqueIdentifier, key)
				.AddInputParam("@1", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@2", System.Data.SqlDbType.DateTime, loggedIn)
				.AddInputParam("@3", System.Data.SqlDbType.DateTime, lastAccessed)
				.AddInputParam("@4", System.Data.SqlDbType.Bit, perminant)
            );
        }

        public static List<Dictionary<string, object>> UserLoginKey_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.UserLoginKeys");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> UserLoginKey_Get(this TestConnection source, Guid key)
        {
            string sql = "select * from acms.UserLoginKeys where Key = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.UniqueIdentifier, key)
                ).FirstOrDefault();
        }
	

        public static void UserPostComment_Add(this TestConnection conn, int id, int? userId, int postId, string title, string comment, string iPAddress, bool reviewed, bool reported, bool suspended, bool deleted, DateTime created)
        {
            string sql = @"
            
            set identity_insert acms.UserPostComment on 

            INSERT INTO [acms].UserPostComment ([Id], [UserId], [PostId], [Title], [Comment], [IPAddress], [Reviewed], [Reported], [Suspended], [Deleted], [Created])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10)
            
            set identity_insert acms.UserPostComment off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@2", System.Data.SqlDbType.Int, postId)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, title)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, comment)
				.AddInputParam("@5", System.Data.SqlDbType.VarChar, iPAddress)
				.AddInputParam("@6", System.Data.SqlDbType.Bit, reviewed)
				.AddInputParam("@7", System.Data.SqlDbType.Bit, reported)
				.AddInputParam("@8", System.Data.SqlDbType.Bit, suspended)
				.AddInputParam("@9", System.Data.SqlDbType.Bit, deleted)
				.AddInputParam("@10", System.Data.SqlDbType.DateTime, created)
            );
        }

        public static List<Dictionary<string, object>> UserPostComment_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.UserPostComment");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> UserPostComment_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.UserPostComment where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void UserPostUpload_Add(this TestConnection conn, int id, int userId, int postId, int fileId, string title, string comment, string iPAddress, bool reviewed, bool reported, bool suspended, bool deleted, DateTime created, XmlDocument textFields)
        {
            string sql = @"
            
            set identity_insert acms.UserPostUpload on 

            INSERT INTO [acms].UserPostUpload ([Id], [UserId], [PostId], [FileId], [Title], [Comment], [IPAddress], [Reviewed], [Reported], [Suspended], [Deleted], [Created], [TextFields])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12)
            
            set identity_insert acms.UserPostUpload off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@2", System.Data.SqlDbType.Int, postId)
				.AddInputParam("@3", System.Data.SqlDbType.Int, fileId)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, title)
				.AddInputParam("@5", System.Data.SqlDbType.VarChar, comment)
				.AddInputParam("@6", System.Data.SqlDbType.VarChar, iPAddress)
				.AddInputParam("@7", System.Data.SqlDbType.Bit, reviewed)
				.AddInputParam("@8", System.Data.SqlDbType.Bit, reported)
				.AddInputParam("@9", System.Data.SqlDbType.Bit, suspended)
				.AddInputParam("@10", System.Data.SqlDbType.Bit, deleted)
				.AddInputParam("@11", System.Data.SqlDbType.DateTime, created)
				.AddInputParam("@12", System.Data.SqlDbType.Xml, textFields)
            );
        }

        public static List<Dictionary<string, object>> UserPostUpload_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.UserPostUpload");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> UserPostUpload_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.UserPostUpload where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void UserPostUploadFile_Add(this TestConnection conn, int userPostUploadId, string key, int fileId)
        {
            string sql = @"
            
            set identity_insert acms.UserPostUploadFiles on 

            INSERT INTO [acms].UserPostUploadFiles ([UserPostUploadId], [Key], [FileId])
			VALUES (@0, @1, @2)
            
            set identity_insert acms.UserPostUploadFiles off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, userPostUploadId)
				.AddInputParam("@1", System.Data.SqlDbType.VarChar, key)
				.AddInputParam("@2", System.Data.SqlDbType.Int, fileId)
            );
        }

        public static List<Dictionary<string, object>> UserPostUploadFile_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.UserPostUploadFiles");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> UserPostUploadFile_Get(this TestConnection source, int userPostUploadId, string key)
        {
            string sql = "select * from acms.UserPostUploadFiles where UserPostUploadId = @0 and Key = @1";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, userPostUploadId)
				.AddInputParam("@1", System.Data.SqlDbType.VarChar, key)
                ).FirstOrDefault();
        }
	

        public static void UserPostUploadVote_Add(this TestConnection conn, int id, int userId, int userPostUploadId, decimal? score, DateTime? created)
        {
            string sql = @"
            
            set identity_insert acms.UserPostUploadVote on 

            INSERT INTO [acms].UserPostUploadVote ([Id], [UserId], [UserPostUploadId], [Score], [Created])
			VALUES (@0, @1, @2, @3, @4)
            
            set identity_insert acms.UserPostUploadVote off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@2", System.Data.SqlDbType.Int, userPostUploadId)
				.AddInputParam("@3", System.Data.SqlDbType.Decimal, score)
				.AddInputParam("@4", System.Data.SqlDbType.DateTime, created)
            );
        }

        public static List<Dictionary<string, object>> UserPostUploadVote_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.UserPostUploadVote");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> UserPostUploadVote_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.UserPostUploadVote where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void UserPostVote_Add(this TestConnection conn, int id, int userId, Guid postGuid, decimal? score, DateTime? created)
        {
            string sql = @"
            
            set identity_insert acms.UserPostVote on 

            INSERT INTO [acms].UserPostVote ([Id], [UserId], [PostGuid], [Score], [Created])
			VALUES (@0, @1, @2, @3, @4)
            
            set identity_insert acms.UserPostVote off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@2", System.Data.SqlDbType.UniqueIdentifier, postGuid)
				.AddInputParam("@3", System.Data.SqlDbType.Decimal, score)
				.AddInputParam("@4", System.Data.SqlDbType.DateTime, created)
            );
        }

        public static List<Dictionary<string, object>> UserPostVote_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.UserPostVote");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> UserPostVote_Get(this TestConnection source, int userId, Guid postGuid)
        {
            string sql = "select * from acms.UserPostVote where UserId = @1 and PostGuid = @2";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@1", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@2", System.Data.SqlDbType.UniqueIdentifier, postGuid)
                ).FirstOrDefault();
        }
	

        public static void UserRole_Add(this TestConnection conn, int id, int userId, int roleId, int siteId, DateTime created, DateTime start, DateTime? end)
        {
            string sql = @"
            
            set identity_insert acms.UserRole on 

            INSERT INTO [acms].UserRole ([Id], [UserId], [RoleId], [SiteId], [Created], [Start], [End])
			VALUES (@0, @1, @2, @3, @4, @5, @6)
            
            set identity_insert acms.UserRole off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, userId)
				.AddInputParam("@2", System.Data.SqlDbType.Int, roleId)
				.AddInputParam("@3", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@4", System.Data.SqlDbType.DateTime, created)
				.AddInputParam("@5", System.Data.SqlDbType.DateTime, start)
				.AddInputParam("@6", System.Data.SqlDbType.DateTime, end)
            );
        }

        public static List<Dictionary<string, object>> UserRole_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.UserRole");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> UserRole_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.UserRole where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	

        public static void User_Add(this TestConnection conn, int id, int? siteId, string firstName, string lastName, string userName, DateTime? dateOfBirth, string emailAddress, bool emailAuthenticated, byte? gender, string address1, string address2, string town, string county, string postCode, string mobileTel, DateTime created, string password, int salt, bool deleted, bool? customBool1, bool? customBool2, bool? customBool3, int? customInt1, int? customInt2, int? customInt3, string customString1, string customString2, string customString3, bool locked, DateTime? lastLogin, DateTime? lastActivity, DateTime? lastChangedPassword, DateTime? lastLocked)
        {
            string sql = @"
            
            set identity_insert acms.Users on 

            INSERT INTO [acms].Users ([Id], [SiteId], [FirstName], [LastName], [UserName], [DateOfBirth], [EmailAddress], [EmailAuthenticated], [Gender], [Address1], [Address2], [Town], [County], [PostCode], [MobileTel], [Created], [Password], [Salt], [Deleted], [CustomBool1], [CustomBool2], [CustomBool3], [CustomInt1], [CustomInt2], [CustomInt3], [CustomString1], [CustomString2], [CustomString3], [Locked], [LastLogin], [LastActivity], [LastChangedPassword], [LastLocked])
			VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21, @22, @23, @24, @25, @26, @27, @28, @29, @30, @31, @32)
            
            set identity_insert acms.Users off
            ";
            conn.Execute(sql, new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
				.AddInputParam("@1", System.Data.SqlDbType.Int, siteId)
				.AddInputParam("@2", System.Data.SqlDbType.VarChar, firstName)
				.AddInputParam("@3", System.Data.SqlDbType.VarChar, lastName)
				.AddInputParam("@4", System.Data.SqlDbType.VarChar, userName)
				.AddInputParam("@5", System.Data.SqlDbType.DateTime, dateOfBirth)
				.AddInputParam("@6", System.Data.SqlDbType.VarChar, emailAddress)
				.AddInputParam("@7", System.Data.SqlDbType.Bit, emailAuthenticated)
				.AddInputParam("@8", System.Data.SqlDbType.TinyInt, gender)
				.AddInputParam("@9", System.Data.SqlDbType.VarChar, address1)
				.AddInputParam("@10", System.Data.SqlDbType.VarChar, address2)
				.AddInputParam("@11", System.Data.SqlDbType.VarChar, town)
				.AddInputParam("@12", System.Data.SqlDbType.VarChar, county)
				.AddInputParam("@13", System.Data.SqlDbType.VarChar, postCode)
				.AddInputParam("@14", System.Data.SqlDbType.VarChar, mobileTel)
				.AddInputParam("@15", System.Data.SqlDbType.DateTime, created)
				.AddInputParam("@16", System.Data.SqlDbType.VarChar, password)
				.AddInputParam("@17", System.Data.SqlDbType.Int, salt)
				.AddInputParam("@18", System.Data.SqlDbType.Bit, deleted)
				.AddInputParam("@19", System.Data.SqlDbType.Bit, customBool1)
				.AddInputParam("@20", System.Data.SqlDbType.Bit, customBool2)
				.AddInputParam("@21", System.Data.SqlDbType.Bit, customBool3)
				.AddInputParam("@22", System.Data.SqlDbType.Int, customInt1)
				.AddInputParam("@23", System.Data.SqlDbType.Int, customInt2)
				.AddInputParam("@24", System.Data.SqlDbType.Int, customInt3)
				.AddInputParam("@25", System.Data.SqlDbType.VarChar, customString1)
				.AddInputParam("@26", System.Data.SqlDbType.VarChar, customString2)
				.AddInputParam("@27", System.Data.SqlDbType.VarChar, customString3)
				.AddInputParam("@28", System.Data.SqlDbType.Bit, locked)
				.AddInputParam("@29", System.Data.SqlDbType.DateTime, lastLogin)
				.AddInputParam("@30", System.Data.SqlDbType.DateTime, lastActivity)
				.AddInputParam("@31", System.Data.SqlDbType.DateTime, lastChangedPassword)
				.AddInputParam("@32", System.Data.SqlDbType.DateTime, lastLocked)
            );
        }

        public static List<Dictionary<string, object>> User_GetAll(this TestConnection source)
        {
            string sql = string.Format("select * from acms.Users");
            return source.ExecuteWithResults(sql);
        }
		

        public static Dictionary<string, object> User_Get(this TestConnection source, int id)
        {
            string sql = "select * from acms.Users where Id = @0";
            return source.ExecuteWithResults(
                sql, 
                new ParamCollection()
				.AddInputParam("@0", System.Data.SqlDbType.Int, id)
                ).FirstOrDefault();
        }
	
    }
}
